﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace Microsoft.Forums.ForumsClient.Views
{
    /// <summary>
    /// Represent an item in the columns tree view
    /// </summary>
    public class ColumnsTreeViewItem : TreeViewItem
    {
        /// <summary>
        /// The level in the tree.  Indicates how far to indent
        /// </summary>
        private int level = -1;

        /// <summary>
        /// Item's hierarchy level in the tree
        /// </summary>
        public int Level
        {
            get
            {
                if (level == -1)
                {
                    ColumnsTreeViewItem parent = ItemsControl.ItemsControlFromItemContainer(this) as ColumnsTreeViewItem;
                    level = (parent != null) ? parent.Level + 1 : 0;
                }
                return level;
            }
        }

        /// <summary>
        /// Creates a new System.Windows.Controls.TreeViewItem to use to display the object.
        /// </summary>
        /// <returns> A new ColumnsTreeViewItem.</returns>
        protected override DependencyObject GetContainerForItemOverride()
        {
            return new ColumnsTreeViewItem();
        }
 
        /// <summary>
        ///  Determines whether an object is a ColumnsTreeViewItem
        /// </summary>
        /// <param name="item">The object to evaluate.</param>
        /// <returns>true if item is a ColumnsTreeViewItem; otherwise, false.</returns>
        protected override bool IsItemItsOwnContainerOverride(object item)
        {
            return item is ColumnsTreeViewItem;
        }

        
    }
}
